//
//  SetStaffBuildTimeCell.m
//  QRMaster
//
//  Created by myApple on 16/5/23.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "SetStaffBuildTimeCell.h"

@interface SetStaffBuildTimeCell()

@property(nonatomic,strong)UIImageView * buildImgView;

@property(nonatomic,strong)UILabel * buildNameLabel;



//@property(nonatomic,strong)UILabel * roomTotalLabel;


@property(nonatomic,strong)AssignBuildTimeModel * InfoModel;

@end

@implementation SetStaffBuildTimeCell
#pragma mark -------init
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * cellId = @"GroupTableViewCell";
    SetStaffBuildTimeCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[SetStaffBuildTimeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self addAllSubView];
    }
    return self;
}

-(void)addAllSubView
{
    [self addSubview:self.buildImgView];
    [self addSubview:self.buildNameLabel];
//    [self addSubview:self.roomTotalLabel];
}

#pragma mark ---------initData
-(void)setData:(AssignBuildTimeModel *)itemInfo
{
    self.InfoModel = itemInfo;
    self.buildNameLabel.text = self.InfoModel.bulidingName;
//    self.roomTotalLabel.text = [NSString stringWithFormat:@"共%d间",self.InfoModel.sumRoom];

}


#pragma mark ----------layout
-(void)layoutSubviews
{
    [super layoutSubviews];
    float x = 16;
    float y = (self.frame.size.height - 39)/2.0;
    float width = 39;
    float height = 39;
    self.buildImgView.frame = CGRectMake(x, y, width, height);
    
    x += width + 10;
    y = (self.frame.size.height - 20)/2.0;
    width = [self calculateWidth:(self.frame.size.width - x - 32 - 80) string:self.buildNameLabel.text Font:16.0];
    height = 20;
    self.buildNameLabel.frame = CGRectMake(x, y, width, height);
    
//    x += width + 10;
//    width = 100;
//    self.roomTotalLabel.frame = CGRectMake(x, y, width, height);

    
}

#pragma mark -----------lazy

-(UILabel *)buildNameLabel
{
    if (!_buildNameLabel) {
        _buildNameLabel = [[UILabel alloc]init];
        _buildNameLabel.font = [UIFont systemFontOfSize:15.0];
    }
    return _buildNameLabel;
}


//-(UILabel *)roomTotalLabel
//{
//    if (!_roomTotalLabel) {
//        _roomTotalLabel = [[UILabel alloc]init];
//        _roomTotalLabel.font = [UIFont systemFontOfSize:15.0];
//    }
//    return  _roomTotalLabel;
//}


-(UIImageView *)buildImgView
{
    if (!_buildImgView) {
        _buildImgView = [[UIImageView alloc]init];
        _buildImgView.image = [UIImage imageNamed:@"assignTimeImage"];
    }
    return _buildImgView;
}


#pragma mark -- roomNo自适应长度
-(CGFloat)calculateWidth:(CGFloat)width string:(NSString *)str Font:(CGFloat)font
{
    CGSize size =CGSizeMake(width,20);
    
    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:font],NSFontAttributeName,nil];
    
    //ios7方法，获取文本需要的size，限制宽度
    
    CGSize  actualsize =[str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
    return actualsize.width;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
